#version 460
#extension GL_GOOGLE_include_directive : enable


layout(points) in;
layout(triangle_strip, max_vertices=4) out;
//layout(line_strip, max_vertices=6) out;
//layout(points, max_vertices=64) out;


#include "../../../../core/shader_color.h"
#include "../../../../core/shader_tranform.h"




//    xy     z(低位)  z(高位)     w(顶部偏移)
// (UV偏移)  (顶边偏移  宽度)     (Zuv偏移 )
layout(std430, column_major, binding = 4) readonly buffer U4_Buf {
	//m_Text_Coord[0].x			字符宽度所占纹理宽度比例;
	//m_Text_Coord[0].y			字体大小;
	highp ivec4 m_Text_Coord[];
};


 

//layout(location = 0) in vec4 gColor[];

layout(location = 1) in VS_GS_VERTEX {
	int InstanceIndex;
}vertex_in[];





//layout(location = 0) out vec4 vColor;
//layout(location = 1) out float gCoordInstance;
layout(location = 1) out VS_FS_VERTEX {
	vec4		gColor;
	vec3	vUV_Offset;
};


out gl_PerVertex {
	vec4	gl_Position;
	float	gl_PointSize;
};



void main(void){
	// 位置  大小  对齐方式  深度
	mat3x2 mat = m_LP_SD[vertex_in[0].InstanceIndex];
	
	
	vec4 TColor = f_buildColor(InstanceColor[vertex_in[0].InstanceIndex]);
	//vec4 TColor = f_buildColor(InstanceColor[3]);
	//vec2 size = mat[1] - mat[0];
	int strNumn = int(mat[1].y);
	int strOffset = int(mat[2].x);
	

	//mat3x2 fonts = m_Text_Coord[0];
	ivec4 fonts = m_Text_Coord[0];

	vec4 v = vec4(0, 0, 0, 1.0);
	//vec2 uv = ;
	
	//ivec4 fontsUV = m_Text_Coord[m_Text_ID[strOffset]];
	ivec4 fontsUV = m_Text_Coord[strOffset];
	float width = (fontsUV.z>>16);
	//float top = fontsUV.w;
	//float width = 10;
	float size = fonts.y;
	int uv_z = (fontsUV.z<<16)>>16;
	//float size = 10;


	//========================== 面顶构建 ========================
	//顶点
	v.xy = mat[0];
	v.y += fontsUV.w;
	v.xy *= m_Scale;
	v.xy += m_Loc;


	gl_Position = v;
	gl_Position = mat_ProjecView * gl_Position;
	vUV_Offset = vec3(fontsUV.x*size, fontsUV.y*size, uv_z);
	gColor = TColor;
	EmitVertex();

	gl_Position = v;
	gl_Position.y = v.y + size;
	gl_Position = mat_ProjecView * gl_Position;
	vUV_Offset = vec3(fontsUV.x*size, fontsUV.y*size + size, uv_z);
	gColor = TColor;
	EmitVertex();

	gl_Position = v;
	gl_Position.x = v.x + size;
	gl_Position = mat_ProjecView * gl_Position;
	vUV_Offset = vec3(fontsUV.x*size + size, fontsUV.y*size, uv_z);
	gColor = TColor;
	EmitVertex();

	gl_Position = v;
	gl_Position.x = v.x + size;
	gl_Position.y = v.y + size;
	gl_Position = mat_ProjecView * gl_Position;
	vUV_Offset = vec3(fontsUV.x*size + size, fontsUV.y*size + size, uv_z);
	gColor = TColor;
	EmitVertex();
	return;




	gl_Position = v;
	gl_Position.y += size*10;
	gl_Position = mat_ProjecView * gl_Position;
	//UV
	vUV_Offset.xy = fontsUV.xy * (size);
	vUV_Offset.y += 120;
	//vUV_Offset.xy = vec2(60);
	//vUV_Offset.z = (fontsUV.z<<16)>>16;
	vUV_Offset.z = 0;
	gColor = TColor;
	EmitVertex();


	//v.y += size*10;
	gl_Position = v;
	//gl_Position.y += size*10;
	gl_Position = mat_ProjecView * gl_Position;
	//vUV_Offset.y += size;
	vUV_Offset.xy = fontsUV.xy * (size);
	
	
	gColor = TColor;
	EmitVertex();


	//v.x += width*10;
	//v.y -= size*10;
	gl_Position = v;
	gl_Position.x += width*10;
	gl_Position.y += size*10;
	gl_Position = mat_ProjecView * gl_Position;
	//vUV_Offset.x += width;
	vUV_Offset.xy = fontsUV.xy * (size);
	vUV_Offset.x += 120;
	vUV_Offset.y += 120;
	//vUV_Offset.y -= size;
	//vUV_Offset.y -= 120;
	
	gColor = TColor;
	EmitVertex();

	
	//v.y += size*10;
	gl_Position = v;
	gl_Position.x += width*10;
	gl_Position = mat_ProjecView * gl_Position;
	//vUV_Offset.y += size;
	//vUV_Offset.y += 120;
	vUV_Offset.xy = fontsUV.xy * (size);
	vUV_Offset.x += 120;
	

	gColor = TColor;
	EmitVertex();

	
	//EndPrimitive();
	
}



 